package com.starhub.engine.document.utils;

public enum FileType {
    DOC(".doc"),
    DOCX(".docx"),
    XLS(".xls"),
    XLSX(".xlsx"),

    PDF(".pdf"),
    TXT(".txt"),
    MD(".md"),

    // 图片格式
    PNG(".png"),
    JPEG(".jpeg"),
    JPG(".jpg"),
    GIF(".gif"),
    BMP(".bmp"),
    TIFF(".tiff"),
    SVG(".svg"),
    WEBP(".webp"),
    ICO(".ico"),
    PSD(".psd"),
    RAW(".raw"),
    HEIC(".heic"),
    HEIF(".heif"),

    UNKNOWN("");

    private final String extension;

    FileType(String extension) {
        this.extension = extension;
    }

    public String getExtension() {
        return extension;
    }
    // 根据文件名获取类型
    public static FileType fromFileName(String fileName) {
        if (fileName != null && fileName.contains(".")) {
            String ext = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
            for (FileType type : FileType.values()) {
                if (type.getExtension().equals(ext)) {
                    return type;
                }
            }
        }
        return UNKNOWN;
    }
}

